<?php
header("Content-type: text/html; charset=utf-8");
ini_set('display_errors',1);
set_time_limit(0); 
include_once dirname(dirname(dirname(__FILE__))).'/mgtv_init.php';
include_once dirname(dirname(__FILE__)).'/init.php';
$db = nl_get_db(NL_DB_READ);
$db->open();
$db_w = nl_get_db(NL_DB_WRITE);
$db_w->open();
$list = file_get_contents('activate.log');
$list = explode(PHP_EOL, $list);

$i = 0;
$j = 0;
foreach ($list as  $value) {	
	$c2_task_name = str_replace(PHP_EOL, '', $value);
	
	$sql="select * from nns_mgtvbk_c2_task where nns_org_id='jllt' and (nns_type='vod' or nns_type='index') and nns_name='$c2_task_name'";	
	$c2_task_info = nl_db_get_one($sql, $db);
	if($c2_task_info===false||$c2_task_info===null){
		continue;
	}
	if(is_array($c2_task_info)){
		if($c2_task_info['nns_action']=='destroy'){
			$state = 3;
		}else if($c2_task_info['nns_action']=='modify'){
			$state = 2;
		}else if($c2_task_info['nns_action']=='add'){
			$state = 1;
		}
		$sql_update = "update nns_mgtvbk_c2_task set nns_modify_time=now(),nns_status=$state where nns_id='{$c2_task_info['nns_id']}'";
		$re = nl_execute_by_db($sql_update, $db_w);
		if($re===false){
			$j++;
		}else{
			$i++;
		}
		//echo $sql_update.PHP_EOL;
	}	
}
echo "OK".$i.PHP_EOL;
echo "FAIL".$j.PHP_EOL;
?>